package com.hzcx.app.simplechat.ui.setting.adapter;

import android.view.View;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.base.BaseActivity;
import com.hzcx.app.simplechat.ui.setting.bean.ChatSearchImgBean;

import java.util.List;

public class ChatSearchImgAdapter extends BaseQuickAdapter<ChatSearchImgBean, BaseViewHolder> {

    private int tag;
    private OnSearchImgListener listener;

    public ChatSearchImgAdapter(@Nullable List<ChatSearchImgBean> data) {
        super(R.layout.rv_item_chat_search_img, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ChatSearchImgBean item) {

        helper.setText(R.id.tv_date, item.getDate());
        ChatSearchImgSubAdapter subAdapter = new ChatSearchImgSubAdapter(item.getMsgData(), tag);
        RecyclerView rvSubImg = helper.getView(R.id.rv_img);
        rvSubImg.setLayoutManager(new GridLayoutManager(mContext, 4));
        rvSubImg.setAdapter(subAdapter);

        subAdapter.setOnItemClickListener((adapter, view, position) -> {
            if(tag==1) {
                if (listener != null) {
                    listener.imgOnClick(helper.getAdapterPosition(), position);
                }
                item.getMsgData().get(position).setSelect(!item.getMsgData().get(position).isSelect());
                subAdapter.notifyDataSetChanged();
            }
        });
    }

    public void setTag(int tag) {
        this.tag = tag;
        notifyDataSetChanged();
    }

    public interface OnSearchImgListener {
        void imgOnClick(int headPos, int contentPos);
    }

    public void setOnSearchImgListener(OnSearchImgListener listener) {
        this.listener = listener;
    }
}
